// 请勿输入特殊字符，且不能以下划线开头和结尾
export const specialRules = new RegExp(
  "^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$"
);

// 仅允许输入数字
export const onlyNumberRules = new RegExp("^[0-9]+$");


// 仅允许输入正整数
export const onlyPositiveNumberRules = new RegExp("^[1-9]\\d*$");
export const decimalRules2 = new RegExp("^[-+]?[0-9]+.[0-9]{0,2}$");
// 仅允许输入正负小数，小数点后最多3位
export const decimalRules3 = new RegExp("^[-+]?[0-9]+.[0-9]{0,3}$");
// 只能输入正负小数或整数或零，小数点后最多两位
export const signedDecimalRules = new RegExp("^[-+]?[0-9]+(?:\\.[0-9]{1,2})?$");
// export const signedDecimalRules = new RegExp("^[-+]?\\d+(?:\\.\\d{1,2})?$");
// 只能输入正数和零，小数点最后最多两位
export const positiveNumberRules = new RegExp("^[0-9]+(?:\\.[0-9]{1,2})?$");
/**
 **数字金额校验(请输入正数或0，且小数点后最多保留digit位)
 * @param {Number} num
 * @param {Number} digit
 * @returns {Boolean}
 */
export function validMoney(num, digit) {
  if (num == 0 || num == null) {
    return true;
  } else {
    const txt =
      "^(?!0+(?:\\.0+)?$)(?:[1-9]\\d*|0)(?:\\.\\d{1," + digit + "})?$";
    const reg = new RegExp(txt);
    return reg.test(num);
  }
}

// 电话校验
export const phoneRules = new RegExp(
  "^(([0+]d{2,3}-)?(0d{2,3})-)(d{7,8})(-(d{3,}))?$"
);

// 手机校验
export const mobileRules = new RegExp("^[1][3,5,7,8][0-9]{9}$");

// 邮箱校验
export const emailRules = new RegExp(
  "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$"
);

// 只能输入数字和字母
export const onlyLetterNumberRules = new RegExp("^[a-zA-Z0-9]+$");
